<?php


namespace app\jiangnan\controller;


use app\jiangnan\config\JNConstants;
use app\service\cxyunService;
use app\utils\Constant;
use app\utils\JwtUtils;
use app\utils\StringUtils;
use think\Controller;
use think\Db;

class Bill extends Controller{
    public function calculatingTempCost(){
        $accessToken=request()->header("accessToken");
        $userResult=JwtUtils::getDecodeToken($accessToken);
        $userid=$userResult["userid"];
        $data["parkingId"]="5369467354105601639";
        $data["plateNumber"]=request()->get("plateNumber");
        $data["timestamp"]=time()."000";
        $notData=array();
        $cxyunApi=new cxyunService();
        $res=$cxyunApi->commonPost("calculatingTempCost",$data,$notData);
        
        $result= json_decode($res,true);
        
        if($result["status"]==0){
            return json(["code"=>500,"msg"=>$result["message"]]);
        }else{
            $result= json_decode($result["Data"],true);
            //查询停车场信息
            $parkingInfo=Db::table("parkinglotinfo")->where("cxyun_parking_id",$result["parkingId"])->find();
            if(empty($parkingInfo)){
                return json(["code"=>500,"msg"=>"停车场信息错误"]);
            }
            $add["parkingId"]=$result["parkingId"];
            
            $add["parkingNo"]=$parkingInfo["parkingNo"];
            $add["parkingName"]=$parkingInfo["parkingName"];
            $add["plateNumber"]= $data["plateNumber"];
            $add["payFee"]=$result["payFee"];
            $add["totalFee"]=$result["totalFee"];
            $add["upayFee"]=$result["upayFee"];
            
            $add["orderNo"]=$result["orderNo"];
            $add["stopTime"]=$result["stopTime"];
            $add["inTime"]=$result["inTime"];
            $add["discountFee"]=$result["discountFee"];
            $add["user_id"]=$userid;;
            $add["createTime"]=date("Y-m-d H:i:s");
            $add["id"]= Db::table("cxyun_query_order_log")->insertGetId($add);
            return json(["code"=>0,"data"=>$add,"msg"=>"查询成功"]);
            //
            // $orderInfo=Db::table("cxyun_query_order")->where("orderNo",$add["orderNo"])->find();
            //  if(empty($orderInfo)){
            //     $add["createTime"]=date("Y-m-d H:i:s");
            //     Db::table("cxyun_query_order")->insert($add);
            //     return json(["code"=>0,"data"=>$add,"msg"=>"查询成功"]);
            // }else{
            //     Db::table("cxyun_query_order")->where("orderNo",$add["orderNo"])->update($add);
            //      return json(["code"=>0,"data"=>$add,"msg"=>"查询成功"]);
            // }
        }
        
    }
    public function createOrder(){

    }
}